package com.gavindon.android.viewmodel

import androidx.lifecycle.viewModelScope
import com.gavindon.android.base.BaseViewModel
import com.gavindon.android.entity.HotTagResult
import com.gavindon.android.entity.SearchResp
import com.gavindon.android.entity.SmartEducationContentResp
import com.gavindon.android.entity.StudyRecordResp
import com.gavindon.android.network.DataResult
import com.gavindon.android.repo.SearchRepo
import kotlinx.coroutines.launch

/**
 * description:
 * Created by liNan on  2022-2-12 13:01
 */
class SearchViewModel : BaseViewModel() {


    private val mRepo = SearchRepo()

    private val hotLiveData = SingleLiveEvent<DataResult<List<HotTagResult>>>()
    private val hotRakingLiveData = SingleLiveEvent<DataResult<List<SmartEducationContentResp>>>()
    private val searchResultLiveData = SingleLiveEvent<DataResult<List<SearchResp>>>()

    fun getHotSearch(): SingleLiveEvent<DataResult<List<HotTagResult>>> {
        viewModelScope.launch {
            val resp = mRepo.getHotSearch()
            hotLiveData.value = resp
        }
        return hotLiveData
    }

    fun getSearchRaking(): SingleLiveEvent<DataResult<List<SmartEducationContentResp>>> {
        viewModelScope.launch {
            val resp = mRepo.getSearchRaking()
            hotRakingLiveData.value = resp
        }
        return hotRakingLiveData
    }

    fun getSearchResult(
        pinyin: String,
        word: String
    ): SingleLiveEvent<DataResult<List<SearchResp>>> {
        viewModelScope.launch {
            val resp = mRepo.getSearchResult(pinyin, word)
            searchResultLiveData.value = resp
        }
        return searchResultLiveData
    }

}